package com.lzs.bootsafety.business.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzs.bootsafety.business.sys.entity.SysPost;
import com.lzs.bootsafety.business.sys.entity.SysUser;
import com.lzs.bootsafety.business.sys.mapper.SysPostMapper;
import com.lzs.bootsafety.business.sys.service.SysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SysPostServiceImpl implements SysPostService {
    @Autowired
    private SysPostMapper sysPostMapper;
    @Override
    public List<SysPost> getPostList() {
        return sysPostMapper.selectPostList();
    }

    @Override
    public List<Long> getPostIdsByUserId(Long userId) {
        return sysPostMapper.selectPostIdsByUserId(userId);
    }

    @Override
    public PageInfo<SysPost> getPostByPage(SysPost sysPost) {
        Integer page = sysPost.getPage();
        Integer limit = sysPost.getLimit();
        PageHelper.startPage(page = page == null ? 1 : page,limit = limit == null ? 10 : limit);
        List<SysPost> sysPostList = sysPostMapper.selectPostByPage(sysPost);
        return new PageInfo<SysPost>(sysPostList);
    }

    @Override
    public int addSelective(SysPost sysPost) {
        return sysPostMapper.insertSelective(sysPost);
    }

    @Override
    public SysPost getByPrimaryKey(Long postId) {
        return sysPostMapper.selectByPrimaryKey(postId);
    }

    @Override
    public int updateSysPost(SysPost sysPost) {
        return sysPostMapper.updateByPrimaryKeySelective(sysPost);
    }

    @Override
    public int batchDel(Long[] postIds) {
        return sysPostMapper.batchDelete(postIds);
    }
}
